package com.util;

import com.config.Config;
import lombok.extern.slf4j.Slf4j;
import org.ho.yaml.exception.YamlException;

import java.io.File;
import java.io.FileNotFoundException;

import org.ho.yaml.Yaml;

/**
 * @author Ricky
 * @date 2020-9-3
 */
@Slf4j
public class ConfigUtil {
    static String yamlPath = "config/config.yaml";

    private static Config config;

    public static Config getConfig() {
        if (config == null) {
            try {
                config = Yaml.loadType(new File(yamlPath), Config.class);
            } catch (FileNotFoundException | YamlException e) {
                log.error("加载配置文件失败", e);
            }
        }
        return config;
    }
}
